package com.hongyan.dao;

import com.hongyan.bean.Class;
import com.hongyan.bean.Test_sys;
import com.hongyan.util.JDBCUtils;

import java.util.List;

public class Test_sysDao {
    public static Object[][] findTested_systemByName(String name) {

            String sql = "select * from test_sys where sys_name like '%"+name+"%' order by sys_id asc;";
            List<Test_sys> query = null;
            query = JDBCUtils.query(sql, Test_sys.class);
            Object[][] tested_systems = new Object[query.size()][];
            for (int i = 0; i < query.size(); i++) {
                tested_systems[i] = query.get(i).toArray();
            }
            return tested_systems;


    }
    public static Object[][] getTested_systemListBySql(String sql) {

            List<Test_sys> query = null;
            query = JDBCUtils.query(sql, Test_sys.class);
            Object[][] tested_systems = new Object[query.size()][];
            for (int i = 0; i < query.size(); i++) {
                tested_systems[i] = query.get(i).toArray();
            }
            return tested_systems;


    }

    public static void deleteTest_sys(String id) {
        String sql = "DELETE FROM test_sys WHERE sys_id = ?;";
        JDBCUtils.update(sql, id);
    }

    public static Test_sys findTest_sysById(String sysId) {
        String sql = "select * from test_sys where sys_id = " + sysId + "; ";
        List<Test_sys> query = null;
        query = JDBCUtils.query(sql, Test_sys.class);
        Test_sys sys = query.get(0);;
        return sys;
    }

    public static int insertSys(Test_sys sys) {

        String sql = "INSERT INTO test_sys  VALUES (?, ?,?,?,?);";
        return JDBCUtils.update(sql, sys.getSys_id(),sys.getSys_name(),sys.getDifficulty(),sys.getLast_time(),sys.getVersion());
    }

    public static int updateSys(Test_sys sys) {

        String sql = "UPDATE test_sys SET sys_name = ?,difficulty = ?,last_time = ?,version = ? WHERE sys_id = ?;";
        return JDBCUtils.update(sql, sys.getSys_name(),sys.getDifficulty(),sys.getLast_time(),sys.getVersion(),sys.getSys_id());
    }
}
